using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NTTHAO.Common;
using NTTHAO.CommonWeb;
using NTTHAO.Web.BL.CommonPage;

public partial class admin_webparts_Plug_ins_Comment_CommentList : System.Web.UI.UserControl
{
    public static readonly int PAGE_SIZE = 30;
    public int _PageNo = 1;
    public int _PageCount = 1;
    public long _TotalItem = -1;
    public string _PageUrl = "";

    public DataTable _List = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Request.QueryString["page"] != null)
            {
                try
                {
                    _PageNo = Convert.ToInt32(Request.QueryString["page"].Trim());
                }
                catch { }
            }
            try
            {
                for (int i = 0; i < Request.QueryString.Count; i++)
                {
                    if (!"page".Equals(Request.QueryString.GetKey(i), StringComparison.OrdinalIgnoreCase)
                        && !"time".Equals(Request.QueryString.GetKey(i), StringComparison.OrdinalIgnoreCase))
                    {
                        _PageUrl += "&" + Request.QueryString.GetKey(i) + "=" + Server.UrlEncode(Request.QueryString[i]);
                    }
                }
                if (_PageUrl.Length > 0)
                {
                    _PageUrl = "?" + _PageUrl.TrimStart('&');
                }
            }
            catch { }

            int siteID = WebGlobal.GetSite().ID;
            int langID = LanguageUtility.GetLanguageID();
            _List = ContentComment.GetPage(siteID, langID, -1, _PageNo, PAGE_SIZE, ref _TotalItem);

            this._PageCount = (int)(this._TotalItem / PAGE_SIZE + (this._TotalItem % PAGE_SIZE != 0 ? 1 : 0));
            this._PageCount = this._PageCount < 1 ? 1 : this._PageCount;

            _PageUrl += (_PageUrl.Length > 0 ? "&" : "?") + "time=" + DateTime.Now.Ticks.ToString() + "&";
        }
        catch (Exception ex)
        {
            HtmlGenericControl ctrl = new HtmlGenericControl("div");
            ctrl.InnerHtml = "<p>" + ex.Message + "</p><p>" + ex.StackTrace.Replace(Environment.NewLine, "<br />");
            this.Controls.Add(ctrl);
        }
    }

    public string GetDeleteUrl(int id)
    {
       return "?type=" + this.Request.QueryString["type"] + "&name=" + this.Request.QueryString["name"] + "&action=delete&id=" + id.ToString("0") + (Request.QueryString["page"] == null ? "" : ("&page="+Request.QueryString["page"]));
    }
}
